//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;
using OpenLS.Drawing.Serialization;

namespace OpenLS.Drawing
{
    public class Shape3D : IOfficeXmlSerializable
    {
        private Bevel bevelB;

        private Bevel bevelT;


        private ColorBase contourColor;
        private int contourW;

        private ColorBase extrusionClr;
        private int extrusionH;

        private PresetMaterialType prstMaterial;
        private int z;
        private OfficeArtExtensionList extLst;

        public Bevel BevelB
        {
            get { return bevelB; }
            set { bevelB = value; }
        }

        public Bevel BevelT
        {
            get { return bevelT; }
            set { bevelT = value; }
        }

        public ColorBase ContourColor
        {
            get { return contourColor; }
            set { contourColor = value; }
        }

        public ColorBase ExtrusionColor
        {
            get { return extrusionClr; }
            set { extrusionClr = value; }
        }

        public PresetMaterialType PresetMaterial
        {
            get { return prstMaterial; }
            set { prstMaterial = value; }
        }

        public int ContourW
        {
            get { return contourW; }
            set { contourW = value; }
        }

        public int ExtrusionH
        {
            get { return extrusionH; }
            set { extrusionH = value; }
        }

        public int Z
        {
            get { return z; }
            set { z = value; }
        }

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.ReadAndSwitch("sp3d", DrawingConstants.DrawingNamespaceUri, false))
            {
                Z = c.GetOptionalInteger("z", 0);
                extrusionH = c.GetOptionalInteger("extrusionH", 0);
                contourW = c.GetOptionalInteger("contourW", 0);
                prstMaterial = c.GetOptionalEnum("prstMaterial", PresetMaterialType.WarmMatte);
                BevelT = c.ReadOptionalElementAs<Bevel>("bevelT");
                BevelB = c.ReadOptionalElementAs<Bevel>("bevelB");
                ExtrusionColor = ColorBase.ReadOptionalColorAs("extrusionClr", c);
                ContourColor = ColorBase.ReadOptionalColorAs("contourClr", c);
                this.extLst = c.ReadOptionalElement<OfficeArtExtensionList>("extLst");
            }
        }


        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.WriteAndSwitch("sp3d", DrawingConstants.DrawingNamespace))
            {
                c.SetOptionalInteger("z", Z, 0);
                c.SetOptionalInteger("extrusionH", extrusionH, 0);
                c.SetOptionalInteger("contourW", contourW, 0);
                c.SetOptionalEnum("prstMaterial", prstMaterial, PresetMaterialType.WarmMatte);
                c.WriteOptionalElementAs(BevelT, "bevelT");
                c.WriteOptionalElementAs(BevelB, "bevelB");
                if (ExtrusionColor != null)
                    ExtrusionColor.WriteXmlAs(c, "extrusionClr");
                if (ContourColor != null)
                    using (WriteContext cc = c.Write("contourClr"))
                    {
                        cc.WriteElement(ContourColor);
                    }
//\\                c.WriteOptionalElementAs(ContourColor, "contourClr");
//                if (contourColor != null)
                //\\                  contourColor.WriteXmlAs("contourClr", c);
                c.WriteOptionalElement(extLst);
            }
        }

        #endregion
    }
}